package com.civil.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.civil.mapper.UserInfoMapper;
import com.civil.service.UserInfoService;


@Service
@Transactional
public class UserInfoServiceImpl implements UserInfoService{

	@Autowired
	UserInfoMapper userInfoMapper;
	
	@Value("${file.url.Qrcode}")
	private String urlQrcode;

	@Value("${file.url.path}")
	private String imgUrl;


	public Map<String, Object> login(Map<String, Object> params) {
		 
		return userInfoMapper.login(params);
	}


	@Override
	public void insert(Map<String, Object> params) {
		params.put("ctime", new Date()); 
		userInfoMapper.insert(params);
	}


	@Override
	public Map<String, Object> findList(Map<String, Object> params) {
		params.put("page",
				(Integer.valueOf(params.get("page").toString()) - 1) * Integer.valueOf(params.get("limit").toString()));
		List<Map<String, Object>> list = userInfoMapper.findList(params);
		for (Map<String, Object> map : list) {
			if(map.containsKey("img")){
				map.put("img", urlQrcode+map.get("img"));
			}
		}
		int count = userInfoMapper.findCount(params);
		params = new HashMap<String, Object>();
		params.put("list", list);
		params.put("count", count);
		return params;
	}


	@Override
	public Map<String, Object> findDetailById(String id) {
		Map<String, Object> result = userInfoMapper.findDetailById(id);
		if(result.containsKey("img")){
			result.put("imgs", urlQrcode+result.get("img"));
		}
		return result;
	}


	@Override
	public void deleteById(String id) {
		userInfoMapper.deleteById(id);
	}

	@Override
	public void updateById(Map<String, Object> params) {
		params.put("utime", new Date());
		userInfoMapper.updateById(params);
	}

	 
	
}
